unit commonetypes;

{$mode objfpc}{$H+}
interface

uses
  Classes, SysUtils, lazutf8,fpcunit,Grids,Dialogs,MaskEdit,Controls,LCLType,ConsoleFrm,strutils,EditBtn,StdCtrls,ComCtrls,Graphics;
type

    TMessageTypeEnum = record
      Error:TMessageType;
      Warrn:TMessageType;
      Info:TMessageType;
      Debug:TMessageType;
    end;
 TOwnType = (ontOwn,ontRent);



const


   MessageTypeEnum:TMessageTypeEnum = (
      Error:msgError;
      Warrn:msgWarrning;
      Info:msgInfo;
      Debug:msgDebugTrace;
     );
  poProjectVersionStr = {$I version.inc};
  poProjectName = 'drivers-training-request';
  poProjectDesc = 'Проект автоматизации процесса регистрации групп обучения водителей транспортных средств в органах ГИБДД МВД РФ';
  poCopyrString = 'Copyright (C) 2012 Leonid Vlasov leoniv@bk.ru';
  poLicString =   'Лицензия: GPL';
  poLicUrl =      'http://www.gnu.org/copyleft/gpl.html';
  poProjectUrl = 'http://code.google.com/p/drivers-training-request';
  poProjectWikiUrl = 'http://code.google.com/p/drivers-training-request/wiki';
  poProjectUrlCaption = 'Сайт проекта: ';
  poProjectWikiCaption = 'Wiki проекта: ';
  poProjectIssuseCaption = 'Сообщить об ошибке: ';
  poProjectIssuseUrl = 'http://code.google.com/p/drivers-training-request/issues/entry';
  {$IF DEFINED(REQUEST_CREATOR)}
  poAppName = 'RequestCreator';
  poAppDesc = 'Утилита создания заявления на регистрацию группы обучения водителей транспортных средств в органах ГИБДД МВД РФ';
  {$ELSEIF DEFINED(REQUEST_REGISTER)}
  poAppName = 'RequestRegister';
  poAppDesc = 'Приложение регистрации групп обучения водителей транспортных средств в органах ГИБДД МВД РФ';
  {$ELSE}
   {$STOP Установите праметр компилятора -dREQUEST_CREATOR для проекта RequestCreator.lpr или  -dREQUEST_REGISTER для проекта RequestRegister.lpr}
  {$ENDIF}
   poAppDocCaption = 'Справка по программе: ';
   poAppDocURL = poProjectWikiUrl+'/'+poAppName;
   poBuildDate = {$I %date%};

 //   poAppUpdateUrl =
   poAppConfigIniFileNAme = poAppName+'.ini';
 //XmlNS
  nsUri = poProjectUrl;
  nsTransferObject = 'obj';
  nsTransferObjectURI = nsUri+'/TransferObject';
  nsField = 'fld';
  nsFieldURI = nsUri+'/field';
  nsTabel = 'tbl';
  nsTabelURI = nsUri+'/TransferOjectTable';

   //Config

  //Widget types
  wtEdit ='TEdit';
  wtGreed ='TStringGrid';
  wtMemo ='TMemo';
  wtMAskEdit ='TMaskEdit';
  wtDateEdit ='TDateEdit';
  wtComboBox = 'TComboBox';
  //Строки для диалогов
  dlgoFileFilter='файл заявления|*.req';
  dlgoFileExt='req';
  dlgoDefFileNamePrefix='Заявление_группа_';
  dlgoFillEmpty='Не заполнено поле: ';
  dlgoGreedEmpty='Не заполнена таблица: ';
  dlgoUnknownEmpty='Есть незаполненные поля.';
  dlgoCellEmptyFormat=' +-- Пустая ячейка Строка: %d Колонка: %S';
  dlgoLableNotFound='Не найдена метка для поля: ';
  dlgoDefFormCaptionPrefix='Заявление ';
  dlgoQuestCaption='Запрос действия у пользователя';
  dlgoQuestExit='Закрыть приложение?';
  dlgoQuestExitWithoutSaving='Закрыть приложение без сохранения?';
  dlgoQuestQuit='Закрыть форму?';
  dlgoQuestQuitWithoutSaving='Выйти без сохранения?';
  dlgoQuestIsModifaide = 'Данные формы были модифицированны.';
  //Строки для caption элементов формы и тп
  strSaveAs='Сохранить Как';
  strSave='Сохранить';
  strOpen='Открыть';
  strNew='Новый';
  strExit='Выход';
  strAbout = 'Справка';
  //Виды лпераций
  opCreatorSaveToFile = 'Сохранить';
  opCreatorReadFromFile = 'Открыть';
  //Сообщения Creatora в консоль
  flCreatorDataIsNotFull = 'Операция <%S> не может быть выполнена. Заполните все поля заявления.';
  flCreatorDataINotCorrect = 'Операция <%S> не может быть выполнена. Найденны некорректные данные.';
  flCreatorIOError = 'Операция <%S> не может быть выполнена. Ошибка Ввода/Вывода.';
  //
  EndOfLine = #13;
var
  OwnerTypeEnum: array[ontOwn..ontRent] of string = ('СОБСТВЕННОСТЬ','АРЕНДА');

  ISOFormatSettings : TFormatSettings = (
  CurrencyFormat: 1;
  NegCurrFormat: 5;
  ThousandSeparator: ',';
  DecimalSeparator: '.';
  CurrencyDecimals: 2;
  DateSeparator: '-';
  TimeSeparator: ':';
  ListSeparator: ',';
  CurrencyString: '$';
  ShortDateFormat: 'y/m/d';
  LongDateFormat: 'YYYY-MM-DD';
  TimeAMString: 'AM';
  TimePMString: 'PM';
  ShortTimeFormat: 'hh:nn';
  LongTimeFormat: 'hh:nn:ss';
  ShortMonthNames: ('Jan','Feb','Mar','Apr','May','Jun',
                    'Jul','Aug','Sep','Oct','Nov','Dec');
  LongMonthNames: ('January','February','March','April','May','June',
                   'July','August','September','October','November','December');
  ShortDayNames: ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
  LongDayNames:  ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
  TwoDigitYearCenturyWindow: 50;
  );
LocalFormatSettings : TFormatSettings = (
  CurrencyFormat: 1;
  NegCurrFormat: 5;
  ThousandSeparator: '.';
  DecimalSeparator: ',';
  CurrencyDecimals: 2;
  DateSeparator: '.';
  TimeSeparator: ':';
  ListSeparator: ',';
  CurrencyString: 'Rub';
  ShortDateFormat: 'd.m.y';
  LongDateFormat: 'DD.MM.YYYY';
  TimeAMString: 'AM';
  TimePMString: 'PM';
  ShortTimeFormat: 'hh:nn';
  LongTimeFormat: 'hh:nn:ss';
  ShortMonthNames: ('Янв','Фев','Март','Апр','Май','Июнь',
                    'Июль','Авг','Сент','Окт','Нояб','Дек');
  LongMonthNames: ('Январь','Февраль','Март','Апрель','Май','Июнь',
                    'Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь');
  ShortDayNames: ('Вос','Пон','Вт','Ср','Чт','Пят','Суб');
  LongDayNames:  ('Воскресенье','Понедельник','Вторник','Среда','Четверг','Пятница','Суббота');
  TwoDigitYearCenturyWindow: 50;
  );


  function DateTimeToISOStr(D:TDateTime):String;
  function ISOStrToDateTime(S:String):TDateTime;
  function NormalizeStr(S:String):String;
  function MyUpperCase(S:String):String;
  function EnToRu(Var S:String):String;//Замняет в строке S все латинские буквы на руские буквы имюшие равное написание
  function RuToEn(Var S:String):String;//Замняет в строке S все руские буквы на латинские буквы имюшие равное написание
  function GetEnChar(RuCahr:TUTF8Char):TUTF8Char;//возвращает латинский символ по русскому с одинаковым написанием
  function GetRuChar(EnChar:TUTF8Char):TUTF8Char;//возвращает русский символ по латинскому с одинаковым написанием
  function IsEmtyStr(const s:String):Boolean;
  function IsEmtyGreed(const g:TCustomStringGrid):Boolean;
  function IsEmptyDate(const d:TDateTime):Boolean;
  function IsEmtyMaskEdit(Me:TMaskEdit):Boolean;
  function ReplaseChare(S: String; oldchar,newchar: char):string;
  function GetDefaultFileName(GroupNumber:String):String;
  function QuestOnExitWitoutSaving(Message:String=''):Integer;
  function QuestOnQuitWitoutSaving(Message:String=''):Integer;
  function QuestOnExit(): Integer;
  function QuestOnQuit(): Integer;
  function Cp866ToUTF8Char(Src:Char):TUTF8Char;
  function Cp866ToCp1251Char(Src: Char): Char;
  procedure ToConsole(Mess:String;MessType:TMessageType);
  function IsWidgetClass(Obj:TObject):Boolean;
  function IsAnsiLitera(c:Char):Boolean;
  function IsUTF8RULitera(c:TUtf8char):Boolean;
  function IsDidgit(c:char):Boolean;

//  procedure ToConsole(ConsMess:TConsoleMsg);

implementation

function DateTimeToISOStr(D: TDateTime): String;
begin
  Result:=FormatDateTime(ISOFormatSettings.LongDateFormat+' '+ISOFormatSettings.LongTimeFormat,D,ISOFormatSettings);
end;

function ISOStrToDateTime(S: String): TDateTime;
begin
  Result:=StrToDateTime(S,ISOFormatSettings);
end;



function NormalizeStr(S: String): String;
const
  dubleSpase=#$20+#$20;
  dubleTub=#9+#9;
var
Pos:PtrInt;
begin
  S:=UTF8Trim(S);
  Pos:=UTF8Pos(dubleSpase,S);
  while Pos<>0 do
  begin
    UTF8Delete(s,Pos,1);
    Pos:=UTF8Pos(dubleSpase,S);
  end;
  Pos:=UTF8Pos(dubleTub,S);
  while Pos<>0 do
  begin
    UTF8Delete(s,Pos,1);
    Pos:=UTF8Pos(dubleTub,S);
  end;
  Result:=UTF8UpperCase(S);
end;

function MyUpperCase(S: String): String;
begin
  Result:=UTF8UpperCase(S);
end;

function EnToRu(var S: String): String;
var
  i: Integer;
begin
    Result:='';
   for i := 1 to UTF8Length(S) do
   begin
     Result:=Result+GetRuChar(UTF8Copy(S,i,1));
   end;
end;

function RuToEn(var S: String): String;
var
  i: Integer;
begin
  Result:='';
  for i := 1 to UTF8Length(S) do
  begin
    Result:=Result+GetEnChar(UTF8Copy(S,i,1));
  end;
end;

function GetEnChar(RuCahr: TUTF8Char): TUTF8Char;
begin
  if RuCahr<#128 then
  begin
   Result:=RuCahr;
   Exit;
  end;
  case RuCahr of
    'а': Result:='a';
    'А': Result:='A';
    'с': Result:='c';
    'С': Result:='C';
    'е': Result:='e';
    'Е': Result:='E';
    'Т': Result:='T';
    'у': Result:='y';
    'о': Result:='o';
    'О': Result:='O';
    'Р': Result:='P';
    'р': Result:='p';
    'Н': Result:='H';
    'К': Result:='K';
    'к': Result:='k';
    'Х': Result:='X';
    'х': Result:='x';
    'В': Result:='B';
    'М': Result:='M';
  else
    Result:=RuCahr;
  end;
end;

function GetRuChar(EnChar: TUTF8Char): TUTF8Char;
begin
  if EnChar>#127 then
  begin
   Result:=EnChar;
   Exit;
  end;
  case EnChar of
    'a': Result:='а';
    'A': Result:='А';
    'c': Result:='с';
    'C': Result:='С';
    'e': Result:='е';
    'E': Result:='Е';
    'T': Result:='Т';
    'y': Result:='у';
    'o': Result:='о';
    'O': Result:='О';
    'P': Result:='Р';
    'p': Result:='р';
    'H': Result:='Н';
    'K': Result:='К';
    'k': Result:='к';
    'X': Result:='Х';
    'x': Result:='х';
    'B': Result:='В';
    'M': Result:='М';
  else
    Result:=EnChar;
  end;
end;

function IsEmtyStr(const s:String):Boolean;
begin
 if UTF8Trim(s)='' then result:=True else result:=False;
end;
function IsEmtyGreed(const g:TCustomStringGrid):Boolean;
var
  i: Integer;
  j: Integer;
begin
  if g.RowCount < 2 then result:=True else
    begin
     for i:= 1 to g.RowCount-1 do
     begin
       for j:= 0 to g.ColCount-1 do
       begin
         if IsEmtyStr(g.Cells[j,i])then
         begin
          result:=True;
          Exit;
         end;
       end;
     end;
    end;
end;
function IsEmptyDate(const d:TDateTime):Boolean;
begin
  if d=0 then result:=True else result:=False;
end;
function IsEmtyMaskEdit(Me: TMaskEdit): Boolean;
begin
  if (Trim(Me.Text) = '') or (Trim(Me.Text) = '/')  then Result:=True else result:=false;
end;

function ReplaseChare(S: String; oldchar,newchar: char): string;
var
  Pos:Integer;
begin
   Pos:=UTF8Pos(oldchar,S);
  while Pos<>0 do
  begin
    UTF8Delete(s,Pos,1);
    UTF8Insert(newchar,s,pos);
    Pos:=UTF8Pos(oldchar,S);
  end;
 Result:=S;
end;

function GetDefaultFileName(GroupNumber: String): String;
begin
  Result:=dlgoDefFileNamePrefix+NormalizeStr(ReplaseChare(GroupNumber,'/','-'))+'.'+dlgoFileExt;
end;

function QuestOnExitWitoutSaving(Message: String): Integer;
begin
  Result:=QuestionDlg(dlgoQuestCaption,dlgoQuestIsModifaide+Message+' '+dlgoQuestExitWithoutSaving,mtConfirmation,[mrYes,mrNo],'');
end;

function QuestOnQuitWitoutSaving(Message: String): Integer;
begin
  Result:=QuestionDlg(dlgoQuestCaption,dlgoQuestIsModifaide+Message+' '+dlgoQuestQuitWithoutSaving,mtConfirmation,[mrYes,mrNo],'');
end;

function QuestOnExit(): Integer;
begin
  Result:=QuestionDlg(dlgoQuestCaption,dlgoQuestExit,mtConfirmation,[mrYes,mrNo],'');
end;

function QuestOnQuit(): Integer;
begin
  Result:=QuestionDlg(dlgoQuestCaption,dlgoQuestQuit,mtConfirmation,[mrYes,mrNo],'');
end;

function Cp866ToUTF8Char(Src: Char): TUTF8Char;
Var
  C:TUTF8Char;
begin
          case Ord(Src) of
                    0..127:Result:=Src;
                    128..175:Result:=#$D0+Char(Ord(Src)+16);
                    //128:Result:='А';   //А
                    //129:Result:='Б';   //Б
                    //130:Result:='В';   //В
                    //131:Result:='Г';   //Г
                    //132:Result:='Д';   //Д
                    //133:Result:='Е';   //Е
                    //134:Result:='Ж';   //Ж
                    //135:Result:='З';   //З
                    //136:Result:='И';   //И
                    //137:Result:='Й';   //Й
                    //138:Result:='К';   //К
                    //139:Result:='Л';   //Л
                    //140:Result:='М';   //М
                    //141:Result:='Н';   //Н
                    //142:Result:='О';   //О
                    //143:Result:='П';   //П
                    //144:Result:='Р';   //Р
                    //145:Result:='С';   //С
                    //146:Result:='Т';   //Т
                    //147:Result:='У';   //У
                    //148:Result:='Ф';   //Ф
                    //149:Result:='Х';   //Х
                    //150:Result:='Ц';   //Ц
                    //151:Result:='Ч';   //Ч
                    //152:Result:='Ш';   //Ш
                    //153:Result:='Щ';   //Щ
                    //154:Result:='Ъ';   //Ъ
                    //155:Result:='Ы';   //Ы
                    //156:Result:='Ь';   //Ь
                    //157:Result:='Э';   //Э
                    //158:Result:='Ю';   //Ю
                    //159:Result:='Я';   //Я
                    //160:Result:='а';   //а
                    //161:Result:='б';   //б
                    //162:Result:='в';   //в
                    //163:Result:='г';   //г
                    //164:Result:='д';   //д
                    //165:Result:='е';   //е
                    //166:Result:='ж';   //ж
                    //167:Result:='з';   //з
                    //168:Result:='и';   //и
                    //169:Result:='й';   //й
                    //170:Result:='к';   //к
                    //171:Result:='л';   //л
                    //172:Result:='м';   //м
                    //173:Result:='н';   //н
                    //174:Result:='о';   //о
                    //175:Result:='п';   //п

                    //176:Result:=#150#226;   //░
                    //177:Result:=#226#146;   //▒
                    //178:Result:=#147#150;   //▓
                    //179:Result:=#150#226;   //│
                    //180:Result:=#226#147;   //┤
                    //181:Result:=#164#148;   //╡
                    //182:Result:=#149#226;   //╢
                    //183:Result:=#226#161;   //╖
                    //184:Result:=#162#149;   //╕
                    //185:Result:=#149#226;   //╣
                    //186:Result:=#226#150;   //║
                    //187:Result:=#149#149;   //╗
                    //188:Result:=#149#226;   //╝
                    //189:Result:=#226#163;   //╜
                    //190:Result:=#145#149;   //╛
                    //191:Result:=#149#226;   //┐
                    //192:Result:=#226#151;   //└
                    //193:Result:=#157#149;   //┴
                    //194:Result:=#149#226;   //┬
                    //195:Result:=#226#156;   //├
                    //196:Result:=#155#149;   //─
                    //197:Result:=#148#226;   //┼
                    //198:Result:=#226#144;   //╞
                    //199:Result:=#148#148;   //╟
                    //200:Result:=#148#226;   //╚
                    //201:Result:=#226#180;   //╔
                    //202:Result:=#172#148;   //╩
                    //203:Result:=#148#226;   //╦
                    //204:Result:=#226#156;   //╠
                    //205:Result:=#128#148;   //═
                    //206:Result:=#148#226;   //╬
                    //207:Result:=#226#188;   //╧
                    //208:Result:=#158#149;   //╨
                    //209:Result:=#149#226;   //╤
                    //210:Result:=#226#159;   //╥
                    //211:Result:=#154#149;   //╙
                    //212:Result:=#149#226;   //╘
                    //213:Result:=#226#148;   //╒
                    //214:Result:=#169#149;   //╓
                    //215:Result:=#149#226;   //╫
                    //216:Result:=#226#166;   //╪
                    //217:Result:=#160#149;   //┘
                    //218:Result:=#149#226;   //┌
                    //219:Result:=#226#144;   //█
                    //220:Result:=#172#149;   //▄
                    //221:Result:=#149#226;   //▌
                    //222:Result:=#226#167;   //▐
                    //223:Result:=#168#149;   //▀


                    224..239:Result:=#$D1+Char(Ord(Src)-96);
                    //224:Result:='р';   //р
                    //225:Result:='с';   //с
                    //226:Result:='т';   //т
                    //227:Result:='у';   //у
                    //228:Result:='ф';   //ф
                    //229:Result:='х';   //х
                    //230:Result:='ц';   //ц
                    //231:Result:='ч';   //ч
                    //232:Result:='ш';   //ш
                    //233:Result:='щ';   //щ
                    //234:Result:='ъ';   //ъ
                    //235:Result:='ы';   //ы
                    //236:Result:='ь';   //ь
                    //237:Result:='э';   //э
                    //238:Result:='ю';   //ю
                    //239:Result:='я';   //я
                    240:Result:=#$D0#$81;   //Ё
                    241:Result:=#$D1#$91;   //ё

                    //242:Result:=#150#226;   //Є
                    //243:Result:=#226#140;   //є
                    //
                    //244:Result:=#144#150;   //Ї
                    //245:Result:=#150#226;   //ї
                    //246:Result:=#209#128;   //Ў
                    //247:Result:=#209#128;   //ў
                    //248:Result:=#209#129;   //°
                    //249:Result:=#209#130;   //∙
                    //250:Result:=#209#131;   //·
                    //251:Result:=#209#132;   //√
                    //252:Result:=#209#133;   //№
                    //253:Result:=#209#134;   //¤
                    //254:Result:=#209#135;   //■
        else
          Result:=#$20;
        end;
end;


function Cp866ToCp1251Char(Src: Char): Char;
Var
  C:TUTF8Char;
begin
          case Ord(Src) of
                    //cp1251 A=#$C0 - п#$EF
                    0..127:Result:=Src;
                    $80..$AF:Result:=Char(Ord(Src)+$40);

                    //128:Result:='А';   //А
                    //129:Result:='Б';   //Б
                    //130:Result:='В';   //В
                    //131:Result:='Г';   //Г
                    //132:Result:='Д';   //Д
                    //133:Result:='Е';   //Е
                    //134:Result:='Ж';   //Ж
                    //135:Result:='З';   //З
                    //136:Result:='И';   //И
                    //137:Result:='Й';   //Й
                    //138:Result:='К';   //К
                    //139:Result:='Л';   //Л
                    //140:Result:='М';   //М
                    //141:Result:='Н';   //Н
                    //142:Result:='О';   //О
                    //143:Result:='П';   //П
                    //144:Result:='Р';   //Р
                    //145:Result:='С';   //С
                    //146:Result:='Т';   //Т
                    //147:Result:='У';   //У
                    //148:Result:='Ф';   //Ф
                    //149:Result:='Х';   //Х
                    //150:Result:='Ц';   //Ц
                    //151:Result:='Ч';   //Ч
                    //152:Result:='Ш';   //Ш
                    //153:Result:='Щ';   //Щ
                    //154:Result:='Ъ';   //Ъ
                    //155:Result:='Ы';   //Ы
                    //156:Result:='Ь';   //Ь
                    //157:Result:='Э';   //Э
                    //158:Result:='Ю';   //Ю
                    //159:Result:='Я';   //Я
                    //160:Result:='а';   //а
                    //161:Result:='б';   //б
                    //162:Result:='в';   //в
                    //163:Result:='г';   //г
                    //164:Result:='д';   //д
                    //165:Result:='е';   //е
                    //166:Result:='ж';   //ж
                    //167:Result:='з';   //з
                    //168:Result:='и';   //и
                    //169:Result:='й';   //й
                    //170:Result:='к';   //к
                    //171:Result:='л';   //л
                    //172:Result:='м';   //м
                    //173:Result:='н';   //н
                    //174:Result:='о';   //о
                    //175:Result:='п';   //п

                    //176:Result:=#150#226;   //░
                    //177:Result:=#226#146;   //▒
                    //178:Result:=#147#150;   //▓
                    //179:Result:=#150#226;   //│
                    //180:Result:=#226#147;   //┤
                    //181:Result:=#164#148;   //╡
                    //182:Result:=#149#226;   //╢
                    //183:Result:=#226#161;   //╖
                    //184:Result:=#162#149;   //╕
                    //185:Result:=#149#226;   //╣
                    //186:Result:=#226#150;   //║
                    //187:Result:=#149#149;   //╗
                    //188:Result:=#149#226;   //╝
                    //189:Result:=#226#163;   //╜
                    //190:Result:=#145#149;   //╛
                    //191:Result:=#149#226;   //┐
                    //192:Result:=#226#151;   //└
                    //193:Result:=#157#149;   //┴
                    //194:Result:=#149#226;   //┬
                    //195:Result:=#226#156;   //├
                    //196:Result:=#155#149;   //─
                    //197:Result:=#148#226;   //┼
                    //198:Result:=#226#144;   //╞
                    //199:Result:=#148#148;   //╟
                    //200:Result:=#148#226;   //╚
                    //201:Result:=#226#180;   //╔
                    //202:Result:=#172#148;   //╩
                    //203:Result:=#148#226;   //╦
                    //204:Result:=#226#156;   //╠
                    //205:Result:=#128#148;   //═
                    //206:Result:=#148#226;   //╬
                    //207:Result:=#226#188;   //╧
                    //208:Result:=#158#149;   //╨
                    //209:Result:=#149#226;   //╤
                    //210:Result:=#226#159;   //╥
                    //211:Result:=#154#149;   //╙
                    //212:Result:=#149#226;   //╘
                    //213:Result:=#226#148;   //╒
                    //214:Result:=#169#149;   //╓
                    //215:Result:=#149#226;   //╫
                    //216:Result:=#226#166;   //╪
                    //217:Result:=#160#149;   //┘
                    //218:Result:=#149#226;   //┌
                    //219:Result:=#226#144;   //█
                    //220:Result:=#172#149;   //▄
                    //221:Result:=#149#226;   //▌
                    //222:Result:=#226#167;   //▐
                    //223:Result:=#168#149;   //▀


                    $E0..$EF:Result:=Char(Ord(Src)+$10);
                    //224:Result:='р';   //р
                    //225:Result:='с';   //с
                    //226:Result:='т';   //т
                    //227:Result:='у';   //у
                    //228:Result:='ф';   //ф
                    //229:Result:='х';   //х
                    //230:Result:='ц';   //ц
                    //231:Result:='ч';   //ч
                    //232:Result:='ш';   //ш
                    //233:Result:='щ';   //щ
                    //234:Result:='ъ';   //ъ
                    //235:Result:='ы';   //ы
                    //236:Result:='ь';   //ь
                    //237:Result:='э';   //э
                    //238:Result:='ю';   //ю
                    //239:Result:='я';   //я
                    240:Result:=#$A8;   //Ё
                    241:Result:=#$B8;   //ё

                    //242:Result:=#150#226;   //Є
                    //243:Result:=#226#140;   //є
                    //
                    //244:Result:=#144#150;   //Ї
                    //245:Result:=#150#226;   //ї
                    //246:Result:=#209#128;   //Ў
                    //247:Result:=#209#128;   //ў
                    //248:Result:=#209#129;   //°
                    //249:Result:=#209#130;   //∙
                    //250:Result:=#209#131;   //·
                    //251:Result:=#209#132;   //√
                    252:Result:=#$B9;   //№
                    //253:Result:=#209#134;   //¤
                    //254:Result:=#209#135;   //■
        else
          Result:=#$20;
        end;
end;


procedure ToConsole(Mess: String; MessType: TMessageType);
var
  Buf:String;
  i: Integer;
begin
  if Mess='' then exit;
  Buf:='';
  if ConsoleForm=nil then
  {$IFDEF DEBUG}
     Raise Exception.Create('Not console found');
  {$else}
     exit;
  {$ENDIF}
  for i:= 1 to Length(Mess) do
  begin
    if Mess[i] <> EndOfLine then
       Buf:=Buf+Mess[i]
    else
      begin
           ConsoleForm.AddTextMessage(Buf,MessType);
           buf:='';
      end;
  end;
  if buf<>'' then  ConsoleForm.AddTextMessage(Buf,MessType);
//  ConsoleForm.AddFutter(DateTimeToStr(now));
  if NOT ConsoleForm.Visible then
     ConsoleForm.Show;
   ConsoleForm.SetFocus;
end;

function IsWidgetClass(Obj: TObject): Boolean;
begin
  Result:=(Obj.ClassType = TEdit)
                         or (Obj.ClassType = TStringGrid)
                         or (Obj.ClassType = TMemo)
                         or (Obj.ClassType = TDateEdit)
                         or (Obj.ClassType = TMaskEdit)
                         or (Obj.ClassType = TComboBox)
                         or (Obj.ClassType = TLabel)
                         ;
end;

function IsAnsiLitera(c: Char): Boolean;
begin
  Result:=(c in ['A'..'z']);
end;

function IsUTF8RULitera(c: TUtf8char): Boolean;
begin
 case c of
 #$d0#$90..#$d0#$bf:Result:=True;
 #$d1#$80..#$d1#$8f:Result:=True;
 #$d0#$81:Result:=True;
 #$D1#$91:Result:=True;
 else
   Result:=False;
 end;
end;

function IsDidgit(c: char): Boolean;
begin
  Result:=(c in  ['0'..'1']);
end;



end.

